﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using ria_project.Web;
using System.ServiceModel.DomainServices.Client;

namespace ria_project
{
    public partial class AdvancedSearch : ChildWindow
    {
        EntitySet<Order> orders;
        public IEnumerable<Order> orderList;
        DomainService1 Inv;
        public AdvancedSearch()
        {
            InitializeComponent();
            Inv = new DomainService1();

            Inv.Load<Order>(Inv.GetOrdersQuery(), i =>
            {
                orders=Inv.Orders;
            }, false);

        }

        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            orderList=orders.Select(i=>i);
            if ((bool)checkBoxEmployee.IsChecked)
                orderList = orderList.Where(i => i.Employee.Name.Equals(EmployeenameTextBox.Text));
            if ((bool)checkBoxItem.IsChecked)
                orderList = orderList.Where(i => i.Item.Name.Equals(ItemnameTextBox1.Text));
            if ((bool)checkBoxOrderID.IsChecked)
                orderList = orderList.Where(i => i.ID.ToString().Equals(OrderiDTextBox.Text));
            if ((bool)checkBoxReason.IsChecked)
                orderList = orderList.Where(i => i.ID.ToString().Equals(reasonTextBox.Text));
            if ((bool)checkBoxStatus.IsChecked)
                orderList = orderList.Where(i => i.Status == statusCheckBox.IsChecked);

            this.DialogResult = true;
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            orders = null;
            this.DialogResult = false;
        }

        private void orderDomainDataSource_LoadedData(object sender, LoadedDataEventArgs e)
        {

            if (e.HasError)
            {
                System.Windows.MessageBox.Show(e.Error.ToString(), "Load Error", System.Windows.MessageBoxButton.OK);
                e.MarkErrorAsHandled();
            }
        }

        private void iDTextBox_TextChanged(object sender, TextChangedEventArgs e)
        {

        }
    }
}

